"""create tables

Revision ID: f7e48c242423
Revises: 
Create Date: 2023-09-22 22:54:40.743603

"""
from typing import Sequence, Union

import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "f7e48c242423"
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "users_tab",
        sa.Column("name", sa.String(), nullable=False),
        sa.Column("api_key", sa.String(), nullable=False),
        sa.Column("id", sa.Integer(), nullable=False),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "follows_tab",
        sa.Column("user_id", sa.Integer(), nullable=False),
        sa.Column("follow_user_id", sa.Integer(), nullable=False),
        sa.Column("id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ["follow_user_id"],
            ["users_tab.id"],
        ),
        sa.ForeignKeyConstraint(
            ["user_id"],
            ["users_tab.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "likes_tab",
        sa.Column("name", sa.String(), nullable=False),
        sa.Column("user_id", sa.Integer(), nullable=False),
        sa.Column("tweet_id", sa.Integer(), nullable=False),
        sa.Column("id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ["tweet_id"],
            ["users_tab.id"],
        ),
        sa.ForeignKeyConstraint(
            ["user_id"],
            ["users_tab.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "tweets_tab",
        sa.Column("content", sa.String(), nullable=False),
        sa.Column("author", sa.Integer(), nullable=False),
        sa.Column("attachments", postgresql.ARRAY(sa.String()), nullable=True),
        sa.Column("views", sa.Integer(), nullable=False),
        sa.Column("id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ["author"],
            ["users_tab.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "medias_tab",
        sa.Column("filename", sa.String(), nullable=False),
        sa.Column("tweet_id", sa.Integer(), nullable=False),
        sa.Column("id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ["tweet_id"],
            ["tweets_tab.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table("medias_tab")
    op.drop_table("tweets_tab")
    op.drop_table("likes_tab")
    op.drop_table("follows_tab")
    op.drop_table("users_tab")
    # ### end Alembic commands ###
